package com.nida.loader;

import java.util.Map;

import blade.kit.Assert;
import blade.kit.CollectionKit;
import blade.kit.StringKit;
import blade.kit.config.Config;

public final class Configurator {


    public static void init(NidaConfig nidaConfig, Config config) {
        Assert.notNull(nidaConfig);
        Assert.notNull(config);
        
        Boolean dev = config.getBoolean("blade.dev");
        
        String httpEncoding = config.getString("blade.http.encoding");
        String httpFilters = config.getString("blade.http.filters");
        String view500 = config.getString("blade.view.500");
        String view404 = config.getString("blade.view.404");
        
        if(null != dev){
            nidaConfig.setDev(dev);
        }
        
        if(StringKit.isNotBlank(httpEncoding)){
            nidaConfig.setEncoding(httpEncoding);
        }
        
        if(StringKit.isNotBlank(httpFilters)){
            nidaConfig.setStaticFolders(httpFilters.split(","));
        }
        
        if(StringKit.isNotBlank(view404)){
            nidaConfig.setView404(view404);
        }
        
        if(StringKit.isNotBlank(view500)){
            nidaConfig.setView500(view500);
        }
        
        Map<String, String> configMap = config.getConfigMap();
        if(CollectionKit.isNotEmpty(configMap)){
            nidaConfig.setConfigMap(configMap);
        }
    }
}
